package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import connection.DbConnection;

public class addMasterCreatorServlet extends HttpServlet {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 533164777309906021L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost (request, response);
	}

	public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		response.setCharacterEncoding("GBK");

		System.out.println("addMasterCreatorServlet run");
		
		// Get parameters
		String selected_poll = request.getSession().getAttribute("selected_poll").toString();
		String poll_master = request.getParameter("poll_master");

		// Error checking
		System.out.println("selected_poll: "+selected_poll);
		System.out.println("poll_creator: "+poll_master);
		
		// Add to user_poll
		DbConnection db = new DbConnection();
		String sql = "Insert into User_Poll Values ('"+poll_master+"',"+selected_poll+","+selected_poll+")";
		System.out.println(sql);
		db.doInsert(sql);
		
		response.sendRedirect("assignUser.jsp");
	}
}
